<div class="block">
	<div class="hd">
		<?php if (isset($view_title)):?><h2><?=$view_title;?></h2><?php endif;?>
	</div>
	<div class="bd">
		<p><?php if (!$archived):?><a href="<?=site_url('companies/'.$current_uri.'/archived');?>">View Archived</a><?php elseif ($archived):?><a href="<?=site_url('companies/'.$current_uri);?>">View Active</a><?php endif;?></p>

		<?php if ($companies):?>


			<table width="100%" class="projects">
				<thead>
				<tr>
					<td>Client</td>
					<td>Main Contact</td>
					<td>Telephone</td>
					<td>Mobile</td>
					<td>URL</td>
				</tr>
				</thead>
				<tbody>
				<?php foreach($companies as $row => $company):?>
				<tr>
					<td><a href="<?=site_url('companies/view/'.$company->company_name);?>"><?=$company->company_name;?></a></td>

					<?php if ($company->contacts):?>
						<?php foreach($company->contacts as $key => $contact):?>
						<td><?=$contact->firstname.' '.$contact->surname;?>&nbsp;</td>
						<td><?php if ($contact->ddi) echo $contact->ddi;?>&nbsp;</td>
						<td><?php if ($contact->mobile) echo $contact->mobile;?>&nbsp;</td>
						<?php if ($key >= 0) break; endforeach;?>
					<?php endif;?>
					<?php if (!$company->contacts):?>

						<td colspan="3">&nbsp;</td>
					<?php endif;?>

					<td><?php if ($company->website):?><a class="external" href="<?=prep_url($company->website);?>">Website</a><?php endif;?></td>

				</tr>
				<?php endforeach;?>
				</tbody>
			</table>


		<?php endif;?>
	</div>
</div>
</div></div></div>



<div id="sidebar" class="yui-b">
	
<?php if ($permissions->addcompany):?>
	<div class="block">
		<div class="hd">
			<h2>Add a New <?php if ($company_type == 'clients'):?>Client
			<?php elseif ($company_type == 'prospects'):?>Prospect
			<?php elseif ($company_type == 'suppliers'):?>Suppliers<?php endif;?></h2>
		</div>
		<div class="bd">
			<?=form_open('companies/add', array('class' => 'formhelper'));?>
			<fieldset>
				<p><label for="company_name" class="required">Company Name</label>
					<input class="text" type="text" name="company_name" id="company_name" value="" class="{required:true}" />
				</p>
				<p><label for="account_code">Account Code</label>
					<input class="text"  type="text" name="account_code" id="account_code" value="" class="" />
				</p>
				<p><label for="website">Web Site</label>
					<input class="text"  type="text" name="website" id="website" value="" class="" />
				</p>
				<p><label for="company_notes" class="">Notes</label>
					<textarea class="text" name="company_notes" id="company_notes"></textarea>
				</p>
				<p><label for="industry">Industry</label>

					<select class="text"  name="industryid" id="industryid" <?php if (!$industries):?>style="display: none;"<?php endif;?>>
						<?php foreach($industries as $industry):?>
							<option value="<?=$industry->id;?>"><?=$industry->industryname;?></option>
						<?php endforeach;?>
					</select>
					<span class="info"><a href="javascript: void(0);" id="industry_industryid_industryname" class="selectadd">Add New Industry</a></span>
					<div id="industry_industryid_industryname_container" style="display: none;">
						<input type="text" name="industry_industryid_industryname_field" id="industry_industryid_industryname_field" value="" /> <button name="industry_industryid_industryname_button" id="industry_industryid_industryname_button">Add</button><a class="cancel">Cancel</a>
					</div>
				</p>
			</fieldset>

			<?php if ($company_type == 'clients'):?><input type="hidden" name="client" value="1" />
			<?php elseif ($company_type == 'prospects'):?><input type="hidden" name="prospect" value="1" />
			<?php elseif ($company_type == 'suppliers'):?><input type="hidden" name="supplier" value="1" /><?php endif;?>

			<input type="submit" class="submit" name="submit" value="Submit" class="" />
		<?=form_close();?>

		</div>
<?php endif;?>
</div>